load(
    "@cmake_configure_file//:cmake_configure_file.bzl",
    "cmake_configure_file",
)
load("@rules_cc//cc:defs.bzl", "cc_library")

package(default_visibility = ["//visibility:public"])

config_setting(
    name = "debug_build",
    values = {"compilation_mode": "dbg"},
)

cmake_configure_file(
    name = "pcl_config_header",
    src = "pcl_config.h.in",
    out = "pcl_config.h",
    cmakelists = [
        "CMakeLists.txt",
    ],
    defines = [
        "PCL_DEV_VERSION=1",
        "PCL_INDEX_SIGNED_STR=false",
        "PCL_INDEX_SIZE=32",
        "PCL_VERSION_MAJOR=1",
        "PCL_VERSION_MINOR=14",
        "PCL_VERSION_PATCH=0",
        "PCL_VERSION_PRETTY=1.14.0-dev",
        "PROJECT_NAME=pcl",
        "VTK_RENDERING_BACKEND_OPENGL_VERSION=2",
        "HAVE_QHULL",
    ] + select({
        "//:debug_build": ["CMAKE_BUILD_TYPE=Debug"],
        "//conditions:default": ["CMAKE_BUILD_TYPE=Release"],
    }),
    visibility = ["//visibility:private"],
)

cc_library(
    name = "pcl_config",
    hdrs = [":pcl_config_header"],
    include_prefix = "pcl",
)

cc_library(
    name = "2d",
    srcs = glob(
        [
            "2d/src/**/*.c",
            "2d/src/**/*.cpp",
            "2d/include/**/*.hpp",
        ],
        exclude = ["2d/src/examples.cpp"],
    ),
    hdrs = glob([
        "2d/include/**/*.h",
        "2d/include/**/*.hh",
    ]),
    includes = ["2d/include"],
    deps = [
        ":common",
        ":filters",
    ],
)

cc_library(
    name = "common",
    srcs = glob([
        "common/src/**/*.c",
        "common/src/**/*.cpp",
        "common/include/**/*.hpp",
    ]),
    hdrs = glob([
        "common/include/**/*.h",
        "common/include/**/*.hh",
    ]),
    includes = ["common/include"],
    deps = [
        ":pcl_config",
        "@boost.algorithm",
        "@boost.assert",
        "@boost.filesystem",
        "@boost.fusion",
        "@boost.mpl",
        "@boost.predef",
        "@boost.preprocessor",
        "@boost.signals2",
        "@eigen",
    ],
)

cc_library(
    name = "features",
    srcs = glob([
        "features/src/**/*.c",
        "features/src/**/*.cpp",
        "features/include/**/*.hpp",
    ]),
    hdrs = glob([
        "features/include/**/*.h",
        "features/include/**/*.hh",
    ]),
    includes = ["features/include"],
    deps = [
        ":2d",
        ":common",
        ":filters",
        ":kdtree",
        ":octree",
        ":search",
        "@boost.graph",
        "@boost.property_map",
        "@eigen",
    ],
)

cc_library(
    name = "filters",
    srcs = glob([
        "filters/src/**/*.c",
        "filters/src/**/*.cpp",
        "filters/include/**/*.hpp",
    ]),
    hdrs = glob([
        "filters/include/**/*.h",
        "filters/include/**/*.hh",
    ]),
    includes = ["filters/include"],
    deps = [
        ":common",
        ":kdtree",
        ":octree",
        ":pcl_config",
        ":sample_consensus",
        ":search",
        "@boost.dynamic_bitset",
        "@boost.fusion",
        "@boost.mpl",
        "@boost.optional",
        "@boost.random",
        "@boost.sort",
        "@eigen",
    ],
)

cc_library(
    name = "geometry",
    srcs = glob([
        "geometry/src/**/*.c",
        "geometry/src/**/*.cpp",
        "geometry/include/**/*.hpp",
    ]),
    hdrs = glob([
        "geometry/include/**/*.h",
        "geometry/include/**/*.hh",
    ]),
    includes = ["geometry/include"],
    deps = [
        ":common",
        "@boost.config",
        "@boost.utility",
        "@eigen",
    ],
)

cc_library(
    name = "io",
    srcs = glob(
        [
            "io/src/**/*.c",
            "io/src/**/*.cpp",
            "io/include/**/*.hpp",
        ],
        exclude = [
            "io/src/davidsdk_grabber.cpp",
            "io/src/depth_sense/**/*.cpp",
            "io/src/depth_sense_grabber.cpp",
            "io/src/dinast_grabber.cpp",
            "io/src/ensenso_grabber.cpp",
            "io/src/oni_grabber.cpp",
            "io/src/openni_camera/**/*.cpp",
            "io/src/openni_grabber.cpp",
            "io/src/openni2/**/*.cpp",
            "io/src/openni2_grabber.cpp",
            "io/src/real_sense/**/*.cpp",
            "io/src/real_sense_grabber.cpp",
            "io/src/real_sense_2_grabber.cpp",
            "io/src/png_io.cpp",
            "io/src/vtk_lib_io.cpp",
        ],
    ),
    hdrs = glob(
        [
            "io/include/**/*.h",
            "io/include/**/*.hh",
        ],
        exclude = [
            "io/include/pcl/io/davidsdk_grabber.h",
            "io/include/pcl/io/depth_sense/**/*.h",
            "io/include/pcl/io/depth_sense_grabber.h",
            "io/include/pcl/io/dinast_grabber.h",
            "io/include/pcl/io/ensenso_grabber.h",
            "io/include/pcl/io/oni_grabber.h",
            "io/include/pcl/io/openni_camera/**/*.h",
            "io/include/pcl/io/openni_grabber.h",
            "io/include/pcl/io/openni2/**/*.h",
            "io/include/pcl/io/openni2_grabber.h",
            "io/include/pcl/io/real_sense/**/*.h",
            "io/include/pcl/io/real_sense_grabber.h",
            "io/include/pcl/io/real_sense_2_grabber.h",
            "io/include/pcl/io/impl/vtk_lib_io.hpp",
            "io/include/pcl/io/png_io.h",
            "io/include/pcl/io/vtk_lib_io.h",
        ],
    ),
    includes = ["io/include"],
    deps = [
        ":common",
        ":octree",
        ":pcl_config",
        "@boost.algorithm",
        "@boost.array",
        "@boost.asio",
        "@boost.circular_buffer",
        "@boost.core",
        "@boost.filesystem",
        "@boost.foreach",
        "@boost.format",
        "@boost.interprocess",
        "@boost.iostreams",
        "@boost.lexical_cast",
        "@boost.math",
        "@boost.mpl",
        "@boost.multiprecision",
        "@boost.numeric_conversion",
        "@boost.predef",
        "@boost.property_tree",
        "@boost.signals2",
        "@boost.smart_ptr",
        "@boost.tokenizer",
        "@boost.utility",
        "@libpng",
    ],
)

cc_library(
    name = "kdtree",
    srcs = glob([
        "kdtree/src/**/*.c",
        "kdtree/src/**/*.cpp",
        "kdtree/include/**/*.hpp",
    ]),
    hdrs = glob([
        "kdtree/include/**/*.h",
        "kdtree/include/**/*.hh",
    ]),
    includes = ["kdtree/include"],
    deps = [
        ":common",
        "@flann//:flann_cpp",
    ],
)

cc_library(
    name = "keypoints",
    srcs = glob([
        "keypoints/**/*.c",
        "keypoints/**/*.cpp",
        "keypoints/include/**/*.hpp",
    ]),
    hdrs = glob([
        "keypoints/include/**/*.h",
        "keypoints/include/**/*.hh",
    ]),
    includes = ["keypoints/include"],
    deps = [
        ":common",
        ":features",
        ":filters",
        ":octree",
        ":pcl_config",
        ":search",
        "@eigen",
    ],
)

cc_library(
    name = "ml",
    srcs = glob([
        "ml/src/**/*.c",
        "ml/src/**/*.cpp",
        "ml/include/**/*.hpp",
    ]),
    hdrs = glob([
        "ml/include/**/*.h",
        "ml/include/**/*.hh",
    ]),
    includes = ["ml/include"],
    deps = [":common"],
)

cc_library(
    name = "octree",
    srcs = glob([
        "octree/src/**/*.c",
        "octree/src/**/*.cpp",
        "octree/include/**/*.hpp",
    ]),
    hdrs = glob([
        "octree/include/**/*.h",
        "octree/include/**/*.hh",
    ]),
    includes = ["octree/include"],
    deps = [
        ":common",
        "@boost.graph",
    ],
)

cc_library(
    name = "people",
    srcs = glob(
        [
            "people/src/**/*.c",
            "people/src/**/*.cpp",
            "people/include/**/*.hpp",
        ],
        exclude = ["people/apps/main_ground_based_people_detection.cpp"],
    ),
    hdrs = glob(
        [
            "people/include/**/*.h",
            "people/include/**/*.hh",
        ],
        exclude = ["include/pcl/people/person_cluster.h"],
    ),
    includes = ["people/include"],
    deps = [
        ":common",
        ":filters",
        ":kdtree",
        ":sample_consensus",
        ":segmentation",
        # ":visualization",
    ],
)

cc_library(
    name = "recognition",
    srcs = glob(
        [
            "recognition/src/**/*.c",
            "recognition/src/**/*.cpp",
            "recognition/include/**/*.hpp",
        ],
        exclude = [
            "recognition/src/hv/hv_go.cpp",
            "recognition/include/pcl/recognition/impl/hv/hv_go.hpp",
        ],
    ),
    hdrs = glob(
        [
            "recognition/include/**/*.h",
            "recognition/include/**/*.hh",
        ],
        exclude = ["recognition/include/pcl/recognition/hv/hv_go.h"],
    ),
    includes = ["recognition/include"],
    deps = [
        ":common",
        ":features",
        ":filters",
        ":io",
        ":kdtree",
        ":ml",
        ":registration",
        ":search",
        "@boost.algorithm",
        "@boost.filesystem",
        "@boost.graph",
        "@boost.random",
        "@eigen",
    ],
)

cc_library(
    name = "registration",
    srcs = glob(
        [
            "registration/src/**/*.c",
            "registration/src/**/*.cpp",
            "registration/include/**/*.hpp",
        ],
        exclude = [
            "registration/include/pcl/registration/impl/transformation_estimation_dq.hpp",
            "registration/src/pairwise_graph_registration.cpp",
            "registration/src/transformation_estimation_dq.cpp",
        ],
    ),
    hdrs = glob(
        [
            "registration/include/**/*.h",
            "registration/include/**/*.hh",
        ],
        exclude = ["registration/include/pcl/registration/transformation_estimation_dq.h"],
    ),
    includes = ["registration/include"],
    deps = [
        ":common",
        ":features",
        ":filters",
        ":kdtree",
        ":sample_consensus",
        ":search",
        "@boost.core",
        "@boost.graph",
        "@boost.property_map",
        "@boost.smart_ptr",
        "@eigen",
    ],
)

cc_library(
    name = "sample_consensus",
    srcs = glob(
        [
            "sample_consensus/src/**/*.c",
            "sample_consensus/src/**/*.cpp",
            "sample_consensus/include/**/*.hpp",
        ],
    ),
    hdrs = glob(
        [
            "sample_consensus/include/**/*.h",
            "sample_consensus/include/**/*.hh",
        ],
    ),
    includes = ["sample_consensus/include"],
    deps = [
        ":common",
        ":pcl_config",
        ":search",
        "@boost.math",
        "@boost.multiprecision",
        "@boost.random",
        "@eigen",
    ],
)

cc_library(
    name = "search",
    srcs = glob([
        "search/src/**/*.c",
        "search/src/**/*.cpp",
        "search/include/**/*.hpp",
    ]),
    hdrs = glob([
        "search/include/**/*.h",
        "search/include/**/*.hh",
    ]),
    includes = ["search/include"],
    deps = [
        ":common",
        ":kdtree",
        ":octree",
        "@eigen",
        "@flann//:flann_cpp",
    ],
)

cc_library(
    name = "segmentation",
    srcs = glob([
        "segmentation/src/**/*.c",
        "segmentation/src/**/*.cpp",
        "segmentation/include/**/*.hpp",
    ]),
    hdrs = glob([
        "segmentation/include/**/*.h",
        "segmentation/include/**/*.hh",
    ]),
    includes = ["segmentation/include"],
    deps = [
        ":common",
        ":features",
        ":filters",
        ":geometry",
        ":ml",
        ":octree",
        ":sample_consensus",
        ":search",
        "@boost.bimap",
        "@boost.concept_check",
        "@boost.graph",
        "@boost.multi_array",
        "@boost.ptr_container",
        "@boost.utility",
        "@eigen",
        "@flann//:flann_cpp",
    ],
)

cc_library(
    name = "surface",
    srcs = glob(
        [
            "surface/src/**/*.c",
            "surface/src/**/*.cpp",
            "surface/include/**/*.hpp",
        ],
        exclude = [
            "surface/src/3rdparty/opennurbs/**/*.c",
            "surface/src/3rdparty/opennurbs/**/*.cpp",
            "surface/src/on_nurbs/**/*.cpp",
            "surface/src/vtk_smoothing/**/*.cpp",
        ],
    ),
    hdrs = glob(
        [
            "surface/include/**/*.h",
            "surface/include/**/*.hh",
        ],
        exclude = [
            "surface/include/pcl/surface/3rdparty/opennurbs/**/*.h",
            "surface/include/pcl/surface/on_nurbs/**/*.h",
            "surface/include/pcl/surface/vtk_smoothing/**/*.h",
        ],
    ),
    includes = ["surface/include"],
    deps = [
        ":common",
        ":kdtree",
        ":octree",
        ":pcl_config",
        ":search",
        "@boost.dynamic_bitset",
        "@eigen",
        "@qhull//:libqhull_r",
    ],
)

cc_library(
    name = "tracking",
    srcs = glob([
        "tracking/src/**/*.c",
        "tracking/src/**/*.cpp",
        "tracking/include/**/*.hpp",
    ]),
    hdrs = glob([
        "tracking/include/**/*.h",
        "tracking/include/**/*.hh",
    ]),
    includes = ["tracking/include"],
    deps = [
        ":common",
        ":filters",
        ":octree",
        ":search",
    ],
)
